/*
 * @(#)Position.java	1.0 2010/06/30
 *
 * Copyright 2010 guyven and David Croft. All rights reserved.
 */
package com.iawg.attrition.game.map;

import com.iawg.attrition.game.units.Targetable;

/**
 * The Position class is used to keep track of places on the Board.
 * To represent a position that is not on the map, the x and y coordinates
 * should be set to -1. If either coordinate is set to -1, the other
 * coordinate will be automatically set to -1. Positions cannot be less
 * than -1 and setting a Position to a number less than -1 will cause an
 * IllegalArgumentException to be thrown.
 * 
 * @author guyven
 * @author William David Croft Jr.
 * @version 1.0 2010/06/30
 */
public class Position implements Targetable {
	/** The x coordinate of this Position. */
	private float x = -1.0f;
	/** The y coordinate of this Position. */
	private float y = -1.0f;
	
	/** Constructor */
	public Position(){
		
	}
	
	/**
	 * Constructs a new Position with a given x and y coordinate.
	 * 
	 * @param x The x coordinate of the new Position
	 * @param y The y coordinate of the new Position
	 */
	public Position(float x, float y){
		setX(x);
		setY(y);
	}

	/** @return the x coordinate of this position. */
	public float getX() {
		return x;
	}
	/** @return the y coordinate of this position. */
	public float getY() {
		return y;
	}

	/**
	 * Setting the x coordinate to -1 will represent a Position
	 * that is not on the map and will automatically set the y
	 * coordinate to -1.
	 * 
	 * @param x The new x coordinate of this position.
	 * @throws IllegalArgumentException If the given coordinate is less than -1.
	 */
	public void setX(float x) {
	  // Position cannot be less than -1
		if(x < -1){
			x = -1;
			throw new IllegalArgumentException("Position coordinate must be equal to or greater than -1.");
		}
		this.x = x;
	  // If x is -1, then y can only be -1 as -1 represents a position not on the board.
		if(x == -1)
			y = -1;
	}

	/**
	 * Setting the y coordinate to -1 will represent a Position
	 * that is not on the map and will automatically set the y
	 * coordinate to -1.
	 * 
	 * @param y The new y coordinate of this position.
	 * @throws IllegalArgumentException If the given coordinate is less than -1.
	 */
	public void setY(float y) {
	  // Position cannot be less than -1
		if(y < -1){
			y = -1;
			throw new IllegalArgumentException("Position coordinate must be equal to or greater than -1.");
		}
		this.y = y;
	  // If y is -1, then x can only be -1 as -1 represents a position not on the board.
		if(y == -1)
			x = -1;
	}

	@Override
	public Position getPosition() {
		return this;
	}

	@Override
	public void setPosition(Position position) {
		
	}
}